// *** LICENSE HEADER ***
// Filename: ./guielement.cpp
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#include "guielement.h"

GLubyte guielement::r = 0;
GLubyte guielement::g = 0;
GLubyte guielement::b = 0;
SDL_Color guielement::textColor = SDL_Color();
SDL_Color guielement::disabledTextColor = SDL_Color();

guielement::guielement(int newPosX, int newPosY, const char* newText, int newId){
    x = newPosX; y = newPosY; id = newId; enabled = true;
    if (!newText)
        textBuffer = NULL;
    else {
        textBuffer = new char[strlen(newText)+1];
        strcpy(textBuffer, newText);
    }
    active = false;
    next = NULL;
}

guielement::~guielement(){
    FreeBuffer();
}

void guielement::SetNext(guielement* newNext){
    next = newNext;
}

void guielement::SetText(const char* newText){
    if (textBuffer)
        FreeBuffer();
    if (newText){
        textBuffer = new char[strlen(newText)+1];
        strcpy(textBuffer, newText);
    } else textBuffer = NULL;
}

guielement* guielement::GetNext(){
    return next;
}

char* guielement::GetText(){
    return textBuffer;
}

void guielement::Enable(){
    enabled = true;
}

void guielement::Disable(){
    enabled = false;
}

bool guielement::IsEnabled(){
    return enabled;
}

void guielement::Deactivate(){
    active = false;
}

void guielement::Activate(){
    active = true;
}

int guielement::GetId(){
    return id;
}

void guielement::SetColors(GLubyte red, GLubyte green, GLubyte blue,
                              GLubyte textRed, GLubyte textGreen, GLubyte textBlue){
    r = red; g = green; b = blue;
    textColor.r = textRed;
    textColor.g = textGreen;
    textColor.b = textBlue;
    disabledTextColor.r = textRed/2;
    disabledTextColor.g = textGreen/2;
    disabledTextColor.b = textBlue/2;
}

void guielement::FreeBuffer(){
    if (textBuffer){
        delete[] textBuffer;
        textBuffer = NULL;
    }
}
